package org.mg.core.service.impl;

import com.google.common.collect.Lists;
import org.mg.core.dao.PageDao;
import org.mg.core.entity.Page;
import org.mg.core.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;

/**
 * @author MG
 * @since 14-04-2013
 */
@Service("pageService")
public class PageServiceImpl implements PageService {

    @Autowired
    PageDao pageDao;

    @Override
    public List<Page> getPages() {
        return Lists.newArrayList(pageDao.findAll());
    }

    @Override
    public Page getPage(long id) {
        checkArgument(id > 0, "getPage: 'id' parameter is invalid");
        return pageDao.getPageDetails(id);
    }
}
